/**
 * MarioEnemy_RedTurtle
 * @extends MarioEnemy
 * @version 2010.12.04
 */
class MarioEnemy_RedTurtle extends MarioEnemy;

var Vector myVelocity;

/**
 * PostBeginPlay
 * @version 2010.12.04
 */
simulated function PostBeginPlay()
{
	Super.PostBeginPlay();

	if(MyController != none)
	{
		MyController = Spawn(class'MarioEnemy_RedTurtleAI', self);
		MyController.SetPawn(self);
	}
	
}

/**
 * AddComponents - unused?
 * @version 2010.12.04
 */
function addComponents()
{
	DetachComponent(NPCMesh);
	NPCMesh = shell;
	//Mesh = shell;
	AttachComponent(shell);
	ForceUpdateComponents(true);
	bCollideWorld = true;
	`log("Adding SHell");
	Velocity.Z = 50;
	DropToGround();
	MaxDesiredSpeed = 200.0f;
	
	
}

/**
 * HitWall
 * @version 2010.12.04
 */
simulated event HitWall(Object.Vector HitNormal, Actor Wall, PrimitiveComponent WallComp)
{
		
		`log("Hit Wall!");
		if(Health <= 50 && Health > 10)
		{
			`log("IF Hit Wall! "$HitNormal);
			if(round(HitNormal.Z) != 1.0)
			{
				if(abs(round(HitNormal.X)) == 1)
					myVelocity.X = myVelocity.X * -1;

				if(abs(round(HitNormal.Y)) == 1)
					myVelocity.Y = myVelocity.Y * -1;
				bCollideWorld = true;

				//`log("reflect, new velocity: "$myVelocity);
			}
		}
		health = 50;
		super.HitWall(HitNormal, Wall, WallComp);
}

/**
 * Bump
 * @version 2010.12.04
 */
event Bump(Actor Other, PrimitiveComponent OtherComp, vector HitNormal)
{
	local GamePawn HitPawn;
	
	`log("HEALTH: "$Health);
	if(Health <= 50 && Health > 10)
	{
		HitPawn = GamePawn(Other);

		if(Velocity.X == 0 && Velocity.Y == 0) 
		{
			`log("NOT MOVING "$HitNormal.X);
			myVelocity.X = abs(HitNormal.X*10000);
			myVelocity.Y = abs(HitNormal.Y*10000);
			myVelocity.Z = 0.0;
			if(HitNormal.X > 0)
				myVelocity.X = myVelocity.X*-1;
			if(HitNormal.Y > 0)
				myVelocity.Y = myVelocity.Y*-1;
			/*
			if (HitPawn.isPlayerPawn()) 
			{
				`log("I make player jump!");
				HitPawn.JumpZ = 1500;
				HitPawn.DoJump(FALSE);
			}
			*/	
			`log("VELOCITY "$myVelocity);
		}
		else 
		{
			if(round(HitNormal.Z) == 1.00){
				Velocity.X = 0;
				Velocity.Y = 0;
				Acceleration = vect(0,0,0);
				myVelocity.X = 0;
				myVelocity.Y = 0;
			}
			else
				Super.Bump(Other, OtherComp, HitNormal);
				
		} 
	}
	else
	{
		Super.Bump(Other, OtherComp, HitNormal);
	}
}



/**
 * Tick
 * @version 2010.12.04
 */
simulated event Tick(float DeltaTime)
{
	if(Health <= 50 && Health > 10)
	{
		Velocity.X = myVelocity.X;
		Velocity.Y = myVelocity.Y;
	}
}


defaultproperties
{
	Begin Object Class=StaticMeshComponent Name=StaticMeshComponent0
		StaticMesh       = StaticMesh'MarioMeshes.RedTurtle';
		LightEnvironment = MyLightEnvironment;
	End Object

	Begin Object Class=StaticMeshComponent Name=StaticMeshComponent1
		StaticMesh       = StaticMesh'MarioMeshes.RedTurtleShell'
		LightEnvironment = MyLightEnvironment;
	End Object

	shell   = StaticMeshComponent1;
	Health  = 100;
	NPCMesh = StaticMeshComponent0
	Mesh    = StaticMeshComponent0
	Components.Add(StaticMeshComponent0);

	bCollideWorld = true;
	bCollideComplex = true;
	bDirectHitWall = true;
	
}
	